package convertedio;

import java.io.*;

public class ConvertedDemo5 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Student s1 = new Student("罗志祥", 16);
        Student s2 = new Student("张三", 23);
        Student s3 = new Student("林则徐", 24);
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("F:\\11\\d.txt"));
        oos.writeObject(s1);
        oos.writeObject(s2);
        oos.writeObject(s3);

        oos.close();

        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("F:\\11\\d.txt"));
        Object obj;
        /*while ((obj=ois.readObject())!=null){
            System.out.println(obj);
        }*/
        // 方式一
        while (true) {
            try {
                System.out.println(ois.readObject());
            } catch (EOFException e) {
                break;
            }
        }
        ois.close();
    }
}
